package com.teamclub.sutil

import org.springframework.web.context.request.RequestContextHolder
import org.springframework.web.context.request.ServletRequestAttributes
import javax.servlet.http.HttpServletRequest

object HttpContextUtils {
  def getHttpServletRequest(): HttpServletRequest = {
    RequestContextHolder.getRequestAttributes.asInstanceOf[ServletRequestAttributes].getRequest
  }
  def getDomain() = {
    val request = getHttpServletRequest()
    val url = request.getRequestURL
    url.delete(url.length() - request.getRequestURI.length, url.length()).toString
  }
  def getOrigin() = {
    val request = getHttpServletRequest()
    request.getHeader("Origin")
  }
}
